

# 写一个生成器函数 myrange2(), 功能和 range 函数完全相同

def myrange2(start, stop=None, step=1):
    if stop is None:
        stop = start
        start = 0
    # 当步长为正数时
    cur_number = start
    if step > 0:
        while cur_number < stop:
            yield cur_number
            cur_number += step
    elif step < 0:
        while cur_number > stop:
            yield cur_number
            cur_number += step


L1 = list(myrange2(5))
print('L1:', L1)
L2 = list(myrange2(3, 5))
print('L2:', L2)
L3 = list(myrange2(1, 10, 2))
print('L3:', L3)
L4 = list(myrange2(10, 0, -3))
print('L4:', L4)
